package com.da.javatest.leetCode2;

import java.util.ArrayList;
import java.util.List;

public class Code500 {
    public static void main(String[] args) {
        new Code500().findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"});
    }

    private String s1 = "qwertyuiop";
    private String s2 = "asdfghjkl";
    private String s3 = "zxcvbnm";

    public String[] findWords(String[] words) {
        List<String> strs = new ArrayList<>();
        for (String word : words) {
            if (isAdd(s1, word) || isAdd(s2, word) || isAdd(s3, word)) {
                strs.add(word);
            }
        }
        return strs.toArray(new String[strs.size()]);
    }

    private boolean isAdd(String key, String word) {
        for (char c : word.toLowerCase().toCharArray()) {
            if (!key.contains(c + "")) {
                return false;
            }
        }
        return true;
    }
}
